package com.itelite.security;

import com.itelite.domain.pojo.LoginUser;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * @author 沈洋 邮箱:1845973183@qq.com
 * @create 2021/8/6-9:44
 **/
public class MyAuthenticationToken extends UsernamePasswordAuthenticationToken {
    private static final long serialVersionUID = 550L;
    private final Object principal;
    private Object credentials;
    private LoginUser loginUser;
    public MyAuthenticationToken(Object principal, Object credentials) {
        super(principal,credentials);
        this.principal = principal;
        this.credentials = credentials;
        this.setAuthenticated(false);
    }

    public MyAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities, LoginUser loginUser) {
        super(principal,credentials,authorities);
        this.principal = principal;
        this.credentials = credentials;
        super.setAuthenticated(true);
        this.loginUser = loginUser;
    }

    public Object getCredentials() {
        return this.credentials;
    }

    public Object getPrincipal() {
        return this.principal;
    }

    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        super.setAuthenticated(false);
    }

    public void eraseCredentials() {
        super.eraseCredentials();
        this.credentials = null;
    }

    public LoginUser getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(LoginUser loginUser) {
        this.loginUser = loginUser;
    }
}
